package com.tencent.cloud.iov.block;

import android.content.Context;
import android.support.annotation.NonNull;

/**
 * 区块布局管理类
 *
 * 用于管理应用上下文信息 Context，及区块布局创建工厂
 *
 * @author showxiao
 * @date 2018/4/18
 */

public class BlockManager {

    private static Context sContext;
    private static IBlockLayoutFactory sFactory;

    /**
     * 初始化上下文，并指定区块布局创建工厂
     *
     * @param context
     * @param layoutFactory
     */
    public static void init(@NonNull Context context, @NonNull IBlockLayoutFactory layoutFactory) {
        sContext = context.getApplicationContext();
        sFactory = layoutFactory;
    }

    /**
     * 获取上下文
     *
     * @return
     */
    public static Context getContext() {
        return sContext;
    }

    /**
     * 创建区块布局
     *
     * @param itemClass
     * @return
     */
    public static <T> IBlockLayout<T> createBlockLayout(Class<? extends T> itemClass) {
        return sFactory.create(itemClass);
    }

}
